/*
 * GraphicsObjectEditorFactory.java
 *
 * Created on 19. huhtikuuta 2007, 23:56
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package flowchart.editors;

import flowchart.nodes.*;
import java.util.*;

/**
 *
 * @author jl
 */
public class GraphicsObjectEditorFactory {
    
    protected HashMap<Class, Class> editorClasses;
    
    /** Creates a new instance of GraphicsObjectEditorFactory */
    public GraphicsObjectEditorFactory() {
        editorClasses = new HashMap();
    }
    
    public void registerEditorClass(Class objectClass, Class editorClass) {
        editorClasses.put(objectClass, editorClass);
    }
    
    public GraphicsObjectEditor getEditor(GraphicsObject obj) {
        GraphicsObjectEditor editor = null;
        if (editorClasses.containsKey(obj.getClass())) {
            Class editorClass = editorClasses.get(obj.getClass());
            try {
                editor = (GraphicsObjectEditor) editorClass.newInstance();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        if (editor == null) {
            editor = new GenericGraphicsObjectEditor();
        }
        editor.setGraphicsObject(obj);
        return editor;
    }
    
}
